<?php
class Core_Data_Mappers_Userrule extends Core_Data_Mappers_Abstract {
	protected $_modelclass = 'Core_Data_Models_Userrule';
	protected $_map = array("Userid"=>"userid","Ruleid"=>"ruleid");
	protected $_businessclass = "Core_Business_Userrule";
	
	public function find($id) {
		$row = $this->getDbTable()->fetchAll(array("userid=?"=>$id));
		if(isset($row) && count($row)==1){
			$output = $this->map($row->current());
			return $output;
		}
		else 
			return null;
	}
	public function add($object){
		if($object instanceof $this->_businessclass) {
			$data = $this->reversemap($object);
			$this->getDbTable()->insert($data);
		}
		
	}
	public function edit($object){
		if($object instanceof $this->_businessclass) {
			$data = $this->reversemap($object);
			unset($data['userid']);
			$this->getDbTable()->update($data,array("userid = ?"=>$object->Userid));
		}
		
	}
	public function exists($object) {
		if($this->find($object->Userid)) {
			return true;
		}
		else 
			return false;
		
	}
}
?>